import 'package:flutter/material.dart';

class SwitchAndCheckBox extends StatefulWidget {
  const SwitchAndCheckBox({super.key});

  @override
  SwitchAndCheckBoxState createState() => SwitchAndCheckBoxState();

}

class SwitchAndCheckBoxState extends State<SwitchAndCheckBox> {
  bool _switchSelected = true; //维护单选开关状态
  bool _checkboxSelected = true; //维护复选框状态

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text("单选开关和复选框"),
      ),
      body: Column(
        children: <Widget>[
          Switch(
              value: _switchSelected,
              onChanged: (value) {
                setState(() {
                  _switchSelected = value;
                });
              }),
          Checkbox(
              value: _checkboxSelected,
              onChanged: (value) {
                setState(() {
                  _checkboxSelected = value!;
                });
              })
        ],
      ),
    );
  }
}
